<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
	<meta charset="UTF-8">
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" href="css/iconfont.css">
	<link rel="stylesheet" href="css/global.css">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="css/swiper.min.css">
	<link rel="stylesheet" href="css/styles.css">
	<link rel="stylesheet" href="css/logo.css" />
	<script src="js/jquery.1.12.4.min.js" charset="UTF-8"></script>
	<script src="js/bootstrap.min.js" charset="UTF-8"></script>
	<script src="js/swiper.min.js" charset="UTF-8"></script>
	<script src="js/global.js" charset="UTF-8"></script>
	<script src="js/jquery.DJMask.2.1.1.js" charset="UTF-8"></script>
	<title>XXX</title>
</head>
<body>
	<!-- 顶部tab -->
	<div id="tbb">
	
	</div>
	<!-- 顶部标题 -->
	<div class="bgf5 clearfix">
		<div class="top-user">
			<div class="inner">
				<a class="logo" href="index.html"> <li id="logo"></li> </a>
				<div class="title">购物车-确认支付</div>
			</div>
		</div>
	</div>
	<div class="content clearfix bgf5">
		<section class="user-center inner clearfix">
			<div class="user-content__box clearfix bgf">
				<div class="title">购物车-确认支付 </div>
				<!--action="http://localhost:16800/pay/pay"-->
				<div class="shop-title">收货地址</div>
				<form class="shopcart-form__box" name="myform" action="http://localhost:16800/pay/pay" method="post">
					<div class="addr-radio" id="address">
						
						
					</div>
					<div class="add_addr"><a href="udai_address.html">添加新地址</a></div>
					<div class="shop-title">确认订单</div>
					<div class="shop-order__detail">
						<table class="table">
							<thead>
								<tr>
									<th width="120"></th>
									<th width="300">商品信息</th>
									<th width="150">单价</th>
									<th width="200">数量</th>
									<th width="200">运费</th>
									<th width="80">总价</th>
								</tr>
							</thead>
							<tbody id="tbody">
								
							</tbody>
						</table>
					</div>
					<div class="shop-cart__info clearfix">
						<div class="pull-left text-left">
							
							<div class="info-line text-nowrap">订单号：<span class="c6" id="ordernumber">10010018</span><input name="orderId" id="ordernumbers" value="" style="display: none;"/></div>
							<div class="info-line text-nowrap">快递方式：<span class="c6" id="logisticscompany">邮政快递包裹</span></div>
							
						</div>
						<div class="pull-right text-right">
							<div class="form-group">
								<label for="coupon" class="control-label">优惠券使用：</label>
								<select id="coupon" name="coupon">
									<option value="-1" selected>- 请选择可使用的优惠券 -</option>
									
								</select>
							</div>
							<script>
								$('#coupon').bind('change',function() {
									console.log($(this).val());
								})
							</script>
							<div class="info-line">优惠活动：<span class="c6">无</span></div>
							<div class="info-line">运费：¥<span class="c6" id="freight">0.00</span></div>
							<div class="info-line"><span class="favour-value" id="discount">已优惠 ¥<span>0.0</span></span>合计：<b class="fz18 cr" id="shopprice"></b><input name="shopPrice" id="zj" value="" style="display: none;"/></div>
							<div class="info-line fz12 c9">（可获 <span class="c6" id="jf"></span> 积分）</div>
						</div>
					</div>
						<!--<div class="radio-line radio-box">
							<label class="radio-label ep">
								<input name="pay" value="1" autocomplete="off" type="radio" checked="checked"><i class="iconfont icon-radio"></i>
								<span class="fz16">支付宝扫码支付</span>
							</label>
							
						</div>-->
					<div class="pay-mode__box">
						<div class="radio-line radio-box">
							<label class="radio-label ep">
								<input name="pay" value="2" autocomplete="off" checked="checked" type="radio"><i class="iconfont icon-radio"></i>
								<img src="images/icons/alipay.png" alt="支付宝支付">
							</label>
							
						</div>
						
					</div>
					
					<div class="user-form-group shopcart-submit">
						<button type="submit" class="btn" id="goorder">继续支付</button>
						
					</div>
					<script>
						$(document).ready(function(){
							$(this).on('change','input',function() {
								$(this).parents('.radio-box').addClass('active').siblings().removeClass('active');
							})
						});
					</script>
				</form>
			</div>
		</section>
	</div>
	<!-- 右侧菜单 -->
	<div class="right-nav">
		<ul class="r-with-gotop">
			<li class="r-toolbar-item">
				<a href="udai_welcome.html" class="r-item-hd">
					<i class="iconfont icon-user" data-badge="0"></i>
					<div class="r-tip__box"><span class="r-tip-text">用户中心</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="udai_shopcart.html" class="r-item-hd">
					<i class="iconfont icon-cart"></i>
					<div class="r-tip__box"><span class="r-tip-text">购物车</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="udai_collection.html" class="r-item-hd">
					<i class="iconfont icon-aixin"></i>
					<div class="r-tip__box"><span class="r-tip-text">我的收藏</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="" class="r-item-hd">
					<i class="iconfont icon-liaotian"></i>
					<div class="r-tip__box"><span class="r-tip-text">联系客服</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="issues.html" class="r-item-hd">
					<i class="iconfont icon-liuyan"></i>
					<div class="r-tip__box"><span class="r-tip-text">留言反馈</span></div>
				</a>
			</li>
			<li class="r-toolbar-item to-top">
				<i class="iconfont icon-top"></i>
				<div class="r-tip__box"><span class="r-tip-text">返回顶部</span></div>
			</li>
		</ul>
		
	</div>
	<!-- 底部信息 -->
	<div class="footer">
		<div class="footer-tags">
			<div class="tags-box inner">
				<div class="tag-div">
					<img src="images/icons/footer_1.gif" alt="厂家直供">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_2.gif" alt="一件代发">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_3.gif" alt="美工活动支持">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_4.gif" alt="信誉认证">
				</div>
			</div>
		</div>
		<div class="footer-links inner">
			<dl>
				<dt>XXX</dt>
				<a href="temp_article/udai_article10.html"><dd>企业简介</dd></a>
				<a href="temp_article/udai_article11.html"><dd>加入U袋</dd></a>
				<a href="temp_article/udai_article12.html"><dd>隐私说明</dd></a>
			</dl>
			<dl>
				<dt>服务中心</dt>
				<a href="temp_article/udai_article1.html"><dd>售后服务</dd></a>
				<a href="temp_article/udai_article2.html"><dd>配送服务</dd></a>
				<a href="temp_article/udai_article3.html"><dd>用户协议</dd></a>
				<a href="temp_article/udai_article4.html"><dd>常见问题</dd></a>
			</dl>
			<dl>
				<dt>新手上路</dt>
				<a href="temp_article/udai_article5.html"><dd>如何成为代理商</dd></a>
				<a href="temp_article/udai_article6.html"><dd>代销商上架教程</dd></a>
				<a href="temp_article/udai_article7.html"><dd>分销商常见问题</dd></a>
				<a href="temp_article/udai_article8.html"><dd>付款账户</dd></a>
			</dl>
		</div>
		<div class="copy-box clearfix">
			<ul class="copy-links">
				<a href="agent_level.html"><li>网店代销</li></a>
				<a href="class_room.html"><li>U袋学堂</li></a>
				<a href="udai_about.html"><li>联系我们</li></a>
				<a href="temp_article/udai_article10.html"><li>企业简介</li></a>
				<a href="temp_article/udai_article5.html"><li>新手上路</li></a>
			</ul>
			<!-- 版权 -->
			<p class="copyright">
				© 2005-2017 XXX 版权所有，并保留所有权利<br>
				ICP备案证书号：闽ICP备XXX号-2&nbsp;&nbsp;&nbsp;&nbsp;福建省宁德市XXX&nbsp;&nbsp;&nbsp;&nbsp;Tel: XXX&nbsp;&nbsp;&nbsp;&nbsp;E-mail: XXX@qq.com
			</p>
		</div>
	</div>
</body>
<script type="text/javascript">
	
	function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
	
	var userid = getCookie("userid");
	
	
	//alert(userid);
	
	$("#tbb").load("index_head.html");
 var i = 1;
 if(i===1)
 {
 	showhb();
 	showcommodity();
 	i=2;
 }

var xx = 0;
	function showcommodity () {
		/**
         * 获取参数的键值对对象。
         * @returns {Object}
         */
        
         
        
       function getUrlVars(){    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

//得到指定参数的value
function getUrlVar(name){
    return getUrlVars()[name];
}
        var price = 0;
       
        var xxx =getUrlVar("cart_id").split(',');
      
	for (var g=0; g < xxx.length; g++) {
		
		$.ajax({
					xhrFields:{withCredentials: true},
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/query_cart",//上s层的路径
					dataType: "json",
				    data:{cart_id:xxx[g]},//传值   				    
				    success: function (data)
					{
						var dataObj=eval("("+JSON.stringify(data)+")");
   		var tbody = document.getElementById("tbody");
   		var zj = document.getElementById("shopprice");
        var zj2 = document.getElementsByName("zj");
        
   		if (dataObj.code>0) {
            			
            			xx++;
							var tr = document.createElement("tr");
							var th = document.createElement("th");
							var a = document.createElement("a");
							var div = document.createElement("div");
							var img = document.createElement("img");
							var td1 = document.createElement("td");
							var div2 = document.createElement("div");
							var input1 = document.createElement("input");
							var input2 = document.createElement("input");
							var div3 = document.createElement("div");
							var td2 = document.createElement("td");
							var td3 = document.createElement("td");
							var td4 = document.createElement("td");
							var td5 = document.createElement("td");
							var sp = document.createElement("span");
							
							th.scope="row";
							a.href="#";
							div.className="img";
							img.src=dataObj.data.commodity_picture;	
							img.id="img"+xx;
							img.className="cover";
						    div2.className="name ep3";
						    div2.innerHTML=dataObj.data.commodity_nametop+" "+dataObj.data.commodity_description
						    input1.name="shopName";
						    input1.value=dataObj.data.commodity_nametop;
						    input1.id="shopName"+xx;
						    input1.style.display="none";
						    input2.name="orderDesc";
						    
						    input2.id="orderDesc"+xx;
						 
						    input2.value=dataObj.data.commodity_description;
						    input2.style.display="none";
						    div3.className="type c9";
						    div3.id="attribute"+xx;
						    div3.innerHTML=dataObj.data.commodity_leixin;
						    td2.innerHTML=dataObj.data.collection_item_price;
						    td2.id="price"+xx;
						    td3.innerHTML=dataObj.data.quantity_of_goods;
						    td3.id="number"+xx;
						    td3.className="gs";
						    td4.innerHTML="￥0.0";
						    td5.innerHTML="￥";
						    sp.innerHTML=dataObj.data.quantity_of_goods*dataObj.data.collection_item_price;
						    sp.id="zjs"+xx;
							//zj.innerHTML="￥"+getParam().quantity*data.data[i].commodity_price;
							//$("#zj").val(getParam().quantity*data.data[i].commodity_price)
							
							tr.appendChild(th);
							th.appendChild(a);
							a.appendChild(div);
							div.appendChild(img);
							tr.appendChild(td1);
							td1.appendChild(div2);
							td1.appendChild(input1);
							td1.appendChild(input2);
							td1.appendChild(div3);
							tr.appendChild(td2);
							tr.appendChild(td3);
							tr.appendChild(td4);
							tr.appendChild(td5);
							td5.appendChild(sp);
							
							tbody.appendChild(tr);
						
							price+=dataObj.data.shopping_Cart_money;
							
							
						
   			//document.getElementById("zj").innerHTML=
   			            zj.innerHTML=price.toFixed(0);
						$("#zj").val(price.toFixed(0));
						
						
						document.getElementById("jf").innerHTML=price.toFixed(0);
   			
   		}
		           		
					}
					})

			
//		$.post("http://localhost:16800/pay/query_cart",
// 	{
// 		cart_id:xxx[g]
// 	},
// 	function (data) {
// 		var dataObj=eval("("+JSON.stringify(data)+")");
// 		var tbody = document.getElementById("tbody");
// 		var zj = document.getElementById("shopprice");
//      var zj2 = document.getElementsByName("zj");
//      
// 		if (dataObj.code>0) {
//          			
//          			xx++;
//							var tr = document.createElement("tr");
//							var th = document.createElement("th");
//							var a = document.createElement("a");
//							var div = document.createElement("div");
//							var img = document.createElement("img");
//							var td1 = document.createElement("td");
//							var div2 = document.createElement("div");
//							var input1 = document.createElement("input");
//							var input2 = document.createElement("input");
//							var div3 = document.createElement("div");
//							var td2 = document.createElement("td");
//							var td3 = document.createElement("td");
//							var td4 = document.createElement("td");
//							var td5 = document.createElement("td");
//							var sp = document.createElement("span");
//							
//							th.scope="row";
//							a.href="#";
//							div.className="img";
//							img.src=dataObj.data.commodity_picture;	
//							img.id="img"+xx;
//							img.className="cover";
//						    div2.className="name ep3";
//						    div2.innerHTML=dataObj.data.commodity_nametop+" "+dataObj.data.commodity_description
//						    input1.name="shopName";
//						    input1.value=dataObj.data.commodity_nametop;
//						    input1.style.display="none";
//						    input2.name="orderDesc";
//						    
//						    input2.id="orderDesc"+xx;
//						 
//						    input2.value=dataObj.data.commodity_description;
//						    input2.style.display="none";
//						    div3.className="type c9";
//						    div3.id="attribute"+xx;
//						    div3.innerHTML=dataObj.data.commodity_leixin;
//						    td2.innerHTML=dataObj.data.collection_item_price;
//						    td2.id="price"+xx;
//						    td3.innerHTML=dataObj.data.quantity_of_goods;
//						    td3.id="number"+xx;
//						    td3.className="gs";
//						    td4.innerHTML="￥0.0";
//						    td5.innerHTML="￥";
//						    sp.innerHTML=dataObj.data.quantity_of_goods*dataObj.data.collection_item_price;
//						    sp.id="zjs"+xx;
//							//zj.innerHTML="￥"+getParam().quantity*data.data[i].commodity_price;
//							//$("#zj").val(getParam().quantity*data.data[i].commodity_price)
//							
//							tr.appendChild(th);
//							th.appendChild(a);
//							a.appendChild(div);
//							div.appendChild(img);
//							tr.appendChild(td1);
//							td1.appendChild(div2);
//							td1.appendChild(input1);
//							td1.appendChild(input2);
//							td1.appendChild(div3);
//							tr.appendChild(td2);
//							tr.appendChild(td3);
//							tr.appendChild(td4);
//							tr.appendChild(td5);
//							td5.appendChild(sp);
//							
//							tbody.appendChild(tr);
//						
//							price+=dataObj.data.shopping_Cart_money;
//							
//							
//						
// 			//document.getElementById("zj").innerHTML=
// 			            zj.innerHTML=price.toFixed(1);
//						$("#zj").val(price.toFixed(1));
//						
//						
//						document.getElementById("jf").innerHTML=price.toFixed(1);
// 			
// 		}
// 	});
   
   	//alert("xx="+xx)
	}
	
	var myDate = new Date();
		var month=myDate.getMonth()+1;
   	    var timestamp = (new Date()).valueOf();
   	    var t = month+"1"+timestamp;
   	    
   	    document.getElementById("ordernumber").innerHTML=t;
   	    document.getElementById("ordernumbers").value=t;
	                    
	}
	
	 var x = 1;
 if(x===1)
 {
 	xxx();
 	x=2;
 }
	
	function xxx(){	
		
		$.ajax({
					xhrFields:{withCredentials: true},
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/showaddress",//上s层的路径
					dataType: "json",
				    data:{
				    	user_id:userid
				    	},//传值
				    success: function (data)
					{
						var dataObj=eval("("+JSON.stringify(data)+")");//转换为json对象 	
            		if (dataObj.data.length>0) {
            			var address = document.getElementById("address");
						for(var x = 0; x < dataObj.data.length; x++) {
							var div = document.createElement("div");
							var label = document.createElement("label");
							var input = document.createElement("input");
							var i = document.createElement("i");
							var a1 = document.createElement("a");
							var a2 = document.createElement("a");
							var span = document.createElement("span");
							
							
							if (dataObj.data[x].status=="1") {
								div.className="radio-line radio-box active";
							}else{
								div.className="radio-line radio-box";
							}
							
							label.className="radio-label ep";
							
							label.title=dataObj.data[x].province+" "+dataObj.data[x].city+" "+dataObj.data[x].area+" "+dataObj.data[x].addressdetailed
							+" ("+dataObj.data[x].addressname+" 收) "+dataObj.data[x].addressphone;
							label.innerHTML=dataObj.data[x].province+" "+dataObj.data[x].city+" "+dataObj.data[x].area+" "+dataObj.data[x].addressdetailed
							+" ("+dataObj.data[x].addressname+" 收) "+dataObj.data[x].addressphone;
							input.name="addr";
							if (dataObj.data[x].status=="1") {
								input.checked="checked";
							}
							input.value=dataObj.data[x].addressid;
							input.name="addr";
							input.autocomplete="off";
							input.type="radio";
							i.className="iconfont icon-radio";
							a1.className="default";
							
							if (dataObj.data[x].status==0) {
								a1.innerHTML="设为默认地址";
								a1.href="#";
							}else{
								a1.innerHTML="默认地址";
								a1.href="#";
							}
							
							a2.href="udai_address_edit.html";
							a2.className="edit";
							a2.innerHTML="修改"
							
							div.appendChild(label);
							label.appendChild(input);
							label.appendChild(i);
							div.appendChild(a1);
							div.appendChild(a2);
							
							address.appendChild(div);
						}
						
					}
		           		
					}
					})
	}
 //	var state = "";
   	function getUrlVars(){ 
        	var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

//得到指定参数的value
function getUrlVar(name){
    return getUrlVars()[name];
}
	
   $("#goorder").click(function() {
   	var yy = 0;
  
        
    //  alert(getUrlVar("cart_id").split(",").length);
   	
   	for (var d = 0; d < getUrlVar("cart_id").split(",").length; d++) {
   		
   		yy++;
   		
        var myDate = new Date();
		var month=myDate.getMonth()+1;
   	    var timestamp = (new Date()).valueOf();
   	    var m = month+"1"+timestamp;
   	    var express = document.getElementById("logisticscompany").innerHTML;
		var description = $("#orderDesc"+yy).val();
		var prices = document.getElementById("price"+yy).innerHTML;
		var number = document.getElementById("number"+yy).innerHTML;
		var img = $("#img"+yy).attr("src");
		var zj = document.getElementById("zjs"+yy).innerHTML;
		var dz = document.myform.addr.value;
		var payment = document.getElementById("zjs"+yy).innerHTML;
		var discount=$("#discount").text();
		var attribute = document.getElementById("attribute"+yy).innerHTML;
		var yf = document.getElementById("freight").innerHTML;
		var jf = document.getElementById("jf").innerHTML;
		var commodity_name = $("#shopName"+yy).val();
	//	alert(commodity_name);
			$.ajax({
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/addorder",//上s层的路径
					dataType: "json",
				    data:{
				    	jifen:jf,
				    	commodity_name:commodity_name,
					state:"结束",
					ordernumber:m,
					userid:userid,
					spid:getUrlVar("cart_id").split(",")[1],
					payway:"",
					orderstatus:"等待买家付款",
					logisticscompany:express,
					comitydescription:description,
					comityprices:prices,
					comitynumber:number,
					comitypicture:img,
					Settlementprice:zj,
					addressid:dz,
					freight:yf,
					actualpayment:payment,
					preferentialinformation:"无优惠",
					specifications:attribute},
				    xhrFields:{withCredentials: true},
				    success: function (data)
					{
						
					}
					})
}
		});
		
		
		function showhb () {
			$.ajax({
					xhrFields:{withCredentials: true},
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/showhb",//上s层的路径
					dataType: "json",
				    data:{
				    	user_id:userid,
				    	},//传值
				    success: function (data)
					{
						var dataObj=eval("("+JSON.stringify(data)+")");//转换为json对象 	
					
					var sel = document.getElementById("coupon");
					
					if (dataObj.data.length>0) {
					
						
						for (var s = 0;s<dataObj.data.length;s++) {
							if (dataObj.data[s].status==1) {
								var op = document.createElement("option");
							var i1 = document.createElement("i");
							var i2 = document.createElement("i");
							var sp1 = document.createElement("span");
							var sp2 = document.createElement("span");
							
							op.value=dataObj.data[s].id;
							if (dataObj.data[s].preferentialway==0) {
								i1.innerHTML="无门槛  ";
							}else{
								sp1.innerHTML=" 满 ￥";
								i1.innerHTML=dataObj.data[s].preferentialway;
							} 
							  sp2 .innerHTML=" 减  ￥";
							 i2.innerHTML=dataObj.data[s].parvalue;
							}
							
							
							
							i1.className="man";
							i2.className="jian";
							op.id=dataObj.data[s].id;
							
							//op.innerHTML="满"+i1+"减"+i2;
							sp1.appendChild(i1);
							sp2.appendChild(i2);
							op.appendChild(sp1);
							op.appendChild(sp2)
							sel.appendChild(op);
						}
						
					}
					
		           		
					}
					})
			

		}
	var quantity = document.getElementById("shopprice").innerHTML;
	
		$("#coupon").change(function(){
			document.getElementById("shopprice").innerHTML=quantity;
			var yhjid = $("#coupon").val();
			//alert(yhjid);
			var price =$("#zj").val();
			
			if ($("#"+yhjid).find(".man").text()==="无门槛  "||$("#"+yhjid).find(".man").text()*1<document.getElementById("shopprice").innerHTML*1) {
				//alert(11111);
			//	alert(price);
				document.getElementById("shopprice").innerHTML=price-$("#"+yhjid).find(".jian").text();
				
				document.getElementById("zj").value=price-$("#"+yhjid).find(".jian").text();
				document.getElementById("jf").innerHTML=price-$("#"+yhjid).find(".jian").text();
			}else if($("#coupon").find(".man").text()*1>document.getElementById("shopprice").innerHTML*1){
				$("#coupon").find("option[value=-1]").attr("selected",true);
				alert('为满足优惠劵体条件哦')
				//selected
				alert(yhjid);
				return;
			}
			
			
			
		});
 
</script>

</html>